]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
switcherPopup: Handle removal of items from SwitcherPopup
authorMario Sanchez Prada <mario@endlessm.com>
Thu, 8 Feb 2018 11:11:11 +0000 (11:11 +0000)
committerFlorian Müllner <florian.muellner@gmail.com>
Fri, 9 Feb 2018 09:26:50 +0000 (09:26 +0000)
This will be mainly useful for closing apps from the applications
switcher, but can be implemented generically enough to select the
nearest existing item after removal if there's any, or destroying
the popup's actor otherwise.

Specifically for the apps switcher, doing this also removes the need
of having to manually either update the current app in AppSwitcher
and highlight it, if there are still any items after the removal, or
simply destroy the AppSwitcher otherwise. Besides, calling _select()
in the handler for item-removed makes sure that the list of thumbnails
in the switcher is always closed, if open, when quitting the app.

https://bugzilla.gnome.org/show_bug.cgi?id=620106

js/ui/altTab.js
js/ui/switcherPopup.js

index 80039cba528dd95b36fcd5b3b50630e188b4e162..407a56e4cc5a6fd5729eacb9b3dd14126ba8da7f 100644 (file)
@@ -812,13 +812,6 @@ var AppSwitcher = new Lang.Class({
 
         this.icons.splice(index, 1);
         this.removeItem(index);
-
-        if (this._curApp == index)
-            this._curApp = SwitcherPopup.mod(index, this.icons.length);
-        if (this.icons.length > 0)
-            this.highlight(this._curApp);
-        else
-            this.actor.destroy();
     },
 });
 
index 9a29ce2c22454006b5016fc30fc8842c717a7c1e..9f92c4598c0e197c88528da94e24514150bba7b5 100644 (file)
@@ -133,6 +133,7 @@ var SwitcherPopup = new Lang.Class({
         this.actor.add_actor(this._switcherList.actor);
         this._switcherList.connect('item-activated', Lang.bind(this, this._itemActivated));
         this._switcherList.connect('item-entered', Lang.bind(this, this._itemEntered));
+        this._switcherList.connect('item-removed', Lang.bind(this, this._itemRemoved));
 
         // Need to force an allocation so we can figure out whether we
         // need to scroll when selecting
@@ -247,6 +248,19 @@ var SwitcherPopup = new Lang.Class({
         this._itemEnteredHandler(n);
     },
 
+    _itemRemovedHandler: function(n) {
+        if (this._items.length > 0) {
+            let newIndex = Math.min(n, this._items.length - 1);
+            this._select(newIndex);
+        } else {
+            this.actor.destroy();
+        }
+    },
+
+    _itemRemoved: function(switcher, n) {
+        this._itemRemovedHandler(n);
+    },
+
     _disableHover: function() {
         this.mouseActive = false;
 
@@ -421,6 +435,7 @@ var SwitcherList = new Lang.Class({
     removeItem: function(index) {
         let item = this._items.splice(index, 1);
         item[0].destroy();
+        this.emit('item-removed', index);
     },
 
     _onItemClicked: function (index) {
@@ -442,15 +457,15 @@ var SwitcherList = new Lang.Class({
             this._items[this._highlighted].remove_style_pseudo_class('selected');
         }
 
-        this._highlighted = index;
-
-        if (this._highlighted != -1) {
+        if (this._items[index]) {
             if (justOutline)
-                this._items[this._highlighted].add_style_pseudo_class('outlined');
+                this._items[index].add_style_pseudo_class('outlined');
             else
-                this._items[this._highlighted].add_style_pseudo_class('selected');
+                this._items[index].add_style_pseudo_class('selected');
         }
 
+        this._highlighted = index;
+
         let adjustment = this._scrollView.hscroll.adjustment;
         let [value, lower, upper, stepIncrement, pageIncrement, pageSize] = adjustment.get_values();
         let [absItemX, absItemY] = this._items[index].get_transformed_position();